package com.example.sport;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.Chronometer;
import android.widget.ImageButton;

public class TimeActivity4 extends AppCompatActivity {
    private Chronometer chronometer1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_time4);
        chronometer1 = findViewById(R.id.chronometer1);


        //设置计时时间为当前时间,(方便监听计时从什么时候开发)
        chronometer1.setBase(SystemClock.elapsedRealtime());
        //设置显示格式
        //        chronometer.setFormat("%s");
        // 更改时间显示格式,默认xml 写的是00:00 ,在计时前面添加文字
        chronometer1.setFormat("%s");
        //启动计时器
        chronometer1.start();

        ImageButton btn=(ImageButton) findViewById(R.id.bn3_finish1);
        btn.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                chronometer1.stop();
                finish();
                return false;
            }
        });
    }




}